package com.raja.servingStation.controller.notice;

import com.alibaba.fastjson.JSONObject;
import com.raja.servingStation.common.constant.MysqlPageVo;
import com.raja.servingStation.common.exception.BusinessRuntimeException;
import com.raja.servingStation.common.util.RequestUtil;
import com.raja.servingStation.common.util.ResponseUtil;
import com.raja.servingStation.entity.ServingStation;
import com.raja.servingStation.entity.vo.NoticeDetail;
import com.raja.servingStation.entity.vo.NoticeReadingDetail;
import com.raja.servingStation.service.NoticeService;
import com.raja.servingStation.service.NoticeViewService;
import com.raja.servingStation.service.ServingStationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 维修站 公文发布 瀑布浏览列表
 */
@Controller
public class NoticeViewController {
    private static final Logger log = LoggerFactory.getLogger(NoticeViewController.class);

    @Autowired
    private ResponseUtil responseUtil;

    @Autowired
    NoticeViewService noticeViewService;

    /**
     * 公文列表接口
     * @param request
     * @return
     */
    @RequestMapping(value = "/noticeView/list", method = RequestMethod.GET)
    public ResponseEntity noticeViewListNew(HttpServletRequest request) {
        try {
            JSONObject body = RequestUtil.parseBody(request);
            MysqlPageVo pageVO = noticeViewService.queryNoticeSubscribeListByPage(body);
            return responseUtil.success(pageVO);
        } catch (BusinessRuntimeException bb) {
            log.error(bb.getMessage(), bb);
            return responseUtil.exception(bb.getMessage());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return responseUtil.exception("查询列表异常");
        }
    }


    /**
     * 公文详情接口
     * @param request
     * @return
     */
    @RequestMapping(value = "/notice/detail", method = RequestMethod.GET)
    public ResponseEntity getNoticeDetail(HttpServletRequest request) {
        try {
            JSONObject body = RequestUtil.parseBody(request);
            NoticeDetail noticeDetail = noticeViewService.queryNoticeDetail(body);
            return responseUtil.success(noticeDetail);
        } catch (BusinessRuntimeException bb) {
            log.error(bb.getMessage(), bb);
            return responseUtil.exception(bb.getMessage());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return responseUtil.exception("查询公告详情异常");
        }
    }

}
